<!-- subpkg_consult/patient/index.vue -->
<script setup>
	import { computed, ref, watch } from 'vue'
	import { reqpatientList } from '../../services/patient'
	import { useConsultStore } from '../../stores/consult'

	let patientList = ref([])
	let defaultFlag = ref(0)

	// 侧滑按钮配置
	const swipeOptions = ref([
		{
			text: '删除',
			style: {
				backgroundColor: '#dd524d',
			},
		},
	])
	const getPatientList = async () => {
		const { data } = await reqpatientList()
		patientList.value = data
	}
	const getDefault = (index, id) => {
		defaultFlag.value = index
	}
	const petientId = computed(() => {
		return patientList.value[defaultFlag.value]?.id
	})
	const getPay = () => {
		const cosultStore = useConsultStore()
		cosultStore.petientId = petientId.value
		uni.navigateTo({
			url: '/subpkg_consult/payment/payment',
		})
	}
	getPatientList()
</script>
<template>
	<scroll-page>
		<view class="patient-page">
			<view class="page-header">
				<view class="patient-title"> 请选择患者信息 </view>
				<view class="patient-tips">
					以便医生给出更准确的治疗，信息仅医生可见
				</view>
			</view>
			<uni-swipe-action>
				<uni-swipe-action-item
					v-for="(item, index) in patientList"
					:key="item.id"
					:right-options="swipeOptions"
				>
					<view
						class="archive-card"
						:class="{ active: defaultFlag === index }"
						@click="getDefault(index, item.id)"
					>
						<view class="archive-info">
							<text class="name">{{ item.name }}</text>
							<text class="id-card">{{ item.idCard }}</text>
							<text class="default" v-if="item.defaultFlag">默认</text>
						</view>
						<view class="archive-info">
							<text class="gender">{{ item.gederValue }}</text>
							<text class="age">{{ item.age }}岁</text>
						</view>
						<navigator
							hover-class="none"
							class="edit-link"
							url="/subpkg_archive/form/index"
						>
							<uni-icons
								type="icon-edit"
								size="20"
								color="#16C2A3"
								custom-prefix="iconfont"
							/>
						</navigator>
					</view>
				</uni-swipe-action-item>
			</uni-swipe-action>

			<!-- 添加按钮 -->
			<view v-if="true" class="archive-card">
				<navigator
					class="add-link"
					hover-class="none"
					url="/subpkg_archive/form/index"
				>
					<uni-icons color="#16C2A3" size="24" type="plusempty" />
					<text class="label">添加患者</text>
				</navigator>
			</view>
		</view>
		<!-- 下一步操作 -->
		<view class="next-step">
			<button class="uni-button" @click="getPay">下一步</button>
		</view>
	</scroll-page>
</template>

<style lang="scss">
	@import './index.scss';
</style>
